entry: Fix primary icon allocation in RTL entries
authorTimm Bäder <mail@baedert.org>
Sun, 28 Apr 2019 06:30:18 +0000 (08:30 +0200)
committerTimm Bäder <mail@baedert.org>
Sun, 28 Apr 2019 06:36:36 +0000 (08:36 +0200)
The primary icon is on the right in RTL, so don't offset the text child
to the right for it.
Fixes the text and icon overlapping in the second entry
in tests/testentryicons

gtk/gtkentry.c

index eb48816b391d340b2f2412f483adad171348bcfa..03b7271fd7593d0324ab7ea7d5917e11a4e97d4a 100644 (file)
@@ -1547,6 +1547,7 @@ gtk_entry_size_allocate (GtkWidget *widget,
                          int        height,
                          int        baseline)
 {
+  const gboolean is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
   GtkEntry *entry = GTK_ENTRY (widget);
   GtkEntryPrivate *priv = gtk_entry_get_instance_private (entry);
   gint i;
@@ -1572,8 +1573,8 @@ gtk_entry_size_allocate (GtkWidget *widget,
                           NULL, &icon_width,
                           NULL, NULL);
 
-      if ((gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL && i == GTK_ENTRY_ICON_PRIMARY) ||
-          (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR && i == GTK_ENTRY_ICON_SECONDARY))
+      if ((is_rtl  && i == GTK_ENTRY_ICON_PRIMARY) ||
+          (!is_rtl && i == GTK_ENTRY_ICON_SECONDARY))
         icon_alloc.x = width - icon_width;
       else
         icon_alloc.x = 0;
@@ -1584,7 +1585,9 @@ gtk_entry_size_allocate (GtkWidget *widget,
       gtk_widget_size_allocate (icon_info->widget, &icon_alloc, baseline);
 
       text_alloc.width -= icon_width;
-      if (i == 0)
+
+      if ((!is_rtl  && i == GTK_ENTRY_ICON_PRIMARY) ||
+          (is_rtl && i == GTK_ENTRY_ICON_SECONDARY))
         text_alloc.x += icon_width;
     }